/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFrameConfig.java
 *
 * Created on 31-may-2010, 17:48:27
 */

package GUI;

/**
 *
 * @author aeguzkiza
 */
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import libraries.MultimediaLibrary;
import libraries.LanguageLibrary;
import libraries.MD5encryptor;
import DBConnections.MySQL_Query;
import com.nilo.plaf.nimrod.NimRODLookAndFeel;
import java.awt.Dimension;
import java.lang.String;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import libraries.JTextFieldFilter;
import libraries.XMLReader;
import libraries.FileAutoCompleter;
import model.DB2Hash;
import view.Physician;
import view.Server;
import controller.Controller;
import javax.swing.text.JTextComponent;
import org.dcm4che2.util.UIDUtils;

public final class JFrameConfig extends javax.swing.JFrame {    
    public Dimension screenSize;
    final Controller controller = new Controller();
    MySQL_Query DB = new MySQL_Query();
    MultimediaLibrary MLib = MultimediaLibrary.getInstance();
    LanguageLibrary LLib = new LanguageLibrary();
    MD5encryptor MD5 = new MD5encryptor();
    XMLReader XMLreader = new XMLReader();
    ArrayList<JTextComponent> textFields = new ArrayList<JTextComponent>();
            
    // DEFINICIÓN DE LOS IMAGEICON
    ImageIcon upna = MLib.getImageIcon(1);
    ImageIcon gn = MLib.getImageIcon(2);
    ImageIcon iconV = MLib.getImageIcon(3);
            
    // Global variables.
        // Default values.
        private int Def_DevicePort = 104;       
        private String Def_modalityUID = "OphthalmicVisualFieldStaticPerimetryMeasurementsStorage";
        // Server fields content.        
        private int Def_ServerPort = 11112;
    // Field lenght.
    private int DeviceManufacturerMaxlenght = 64;
    private int StudyUIDMaxlenght = 64;  // Debería ser 24 para que no dé error en JPG2DCM.
    private int UIDMaxlenght = 64;  // It's a combobox.
    private int AdquisitionDeviceMaxlenght = 150;   // It's a combobox.
    private int InstitutionNameMaxlenght = 64;
    private int InstitutionAddressMaxlenght = 64;
    private int DeviceMaxlenght = 16;
    private int ServerMaxlenght = 16;
    private int LocationMaxlenght = 16;
    private int ModalityMaxlenght = 3;
    private int AETitleMaxlenght = 16;
    private int IPMaxlenght = 64;
    private int PortMaxlenght = 5;
    private int PasswordMaxlenght = 10;
    // Physician names.
    private int PerformingPhysicianNameInput2length = 64;
    private int PerformingPhysicianSurnameInput2length = 64;
    private int PerformingPhysicianSurnameInput4length = 64;
    private int PerformingPhysicianIdInput1length = 64;
    // Device fields content.
    private String DeviceManufacturer = "UPNA - SNS/Osasunbidea";
    private String DeviceAETitle;
    private String DeviceLocation;
    private String DeviceIP;
    private int DevicePort;
    private String DeviceUID;
    private String InstanceUID;
    private String AcquisitionDeviceTypeCodeSequence;
    private String InstitutionName;
    private String InstitutionAddress;
    private String StationName;
    private String Modality;
    private String newConfigPassword;
    // Server fields content.
    private String ServerAETitle;
    private String ServerName;
    private String ServerLocation;
    private String ServerIP;
    private int ServerPort;

    private JTextFieldFilter jtff;
    private ResultSet rs;

    /** Creates new form JFrameConfig */
    public JFrameConfig() {
        try {
            UIManager.setLookAndFeel(new NimRODLookAndFeel());
            
            // Get UID values from DCM4CHE2 library (before initComponents).
            ArrayList<String> subtags = new ArrayList<String>();
            subtags.add("uid");
            subtags.add("keyword");
            XMLreader.getData("uids.xml","uid",subtags);    
            
            // Create GUI components.
            initComponents();
                        
            // Add JtextFields to the same group of JTextComponents:            
            textFields.add(UIDValueInput);
            textFields.add(UIDNameInput);
        
            // Add autocolpete property to each JTextComponent: 
            new FileAutoCompleter(textFields, XMLreader.getArrayList(),1);
            
            // Taking server names from DB.
            ArrayList<Server> serverList = controller.getServerNames(); // Gets all servers AET in it's corresponding combobox.
            System.out.println("tabla vacía");
            // Adding servers to jcombobox.
            SelectedServer_Input.addItem(null); // Add the first server with empty value to allow creating a new one.
            for(int i=0;i<serverList.size();i++){
                SelectedServer_Input.addItem(serverList.get(i));
            }
            getPhysicianNames();    // Gets all physicians names in it's corresponding combobox.
            setScreenSize();
        
            int filas = DB.GetMax("device");    // Gets row number on the table.
            rs = DB.SQLquery("SELECT * FROM device");
            rs.first();

            if(filas == 0){ // Initialized table with 0 rows.
                System.out.println("Table DEVICE empty");
            }else{
                //Considerar el caso en el que una celda esta vacía.

                DeviceAETitle = rs.getString("AETitle");
                AETitleInput.setText(DeviceAETitle);

                DeviceLocation = rs.getString("Location");
                LocationInput.setText(DeviceLocation);

                DeviceIP = rs.getString("DeviceIP");
                IPInput.setText(DeviceIP);

                String DevicePort_String = rs.getString("DevicePort");
                if(DevicePort_String != null){
                    DevicePort = Integer.parseInt(DevicePort_String);
                    PortInput.setText(Integer.toString(DevicePort));
                }
                //DeviceManufacturer = rs.getString("Manufacturer");
                DeviceManufacturerInput.setText(DeviceManufacturer);

                DeviceUID = rs.getString("DeviceUID");
                DeviceUIDInput.setText(DeviceUID);

                InstanceUID = rs.getString("TestUID");
                
                int UIDValue = XMLreader.getArrayList().indexOf(InstanceUID);
                if(UIDValue >= 0){                    
                    UIDValueInput.setText(XMLreader.getArrayList().get(UIDValue));                
                    UIDNameInput.setText(XMLreader.getArrayList().get(UIDValue+1));
                }
                
                
                /*UIDComboBox.setSelectedItem(InstanceUID);
                selection = (String) UIDComboBox.getSelectedItem();
                if(!InstanceUID.equals(selection)){ // Selects the first one in case of doesn't match to the defined devices.
                    UIDComboBox.setSelectedIndex(0);
                    InstanceUID = (String) UIDComboBox.getSelectedItem();   //Assign the last selection value to acquisitionDevice variable.
                }*/

                // AcquisitionDeviceTypeCodeSequence Combobox.
                AcquisitionDeviceTypeCodeSequence = rs.getString("AcquisitionDeviceTypeCodeSequence");
                AcquisitionDeviceTypeCS_Input.setSelectedItem(AcquisitionDeviceTypeCodeSequence);

                String selection = (String) AcquisitionDeviceTypeCS_Input.getSelectedItem();
                if(!AcquisitionDeviceTypeCodeSequence.equals(selection)){ // Selects the last one in case of doesn't match to the defined devices.
                    AcquisitionDeviceTypeCS_Input.setSelectedIndex(AcquisitionDeviceTypeCS_Input.getItemCount()-1);
                    AcquisitionDeviceTypeCodeSequence = (String) AcquisitionDeviceTypeCS_Input.getSelectedItem();   //Assign the last selection value to acquisitionDevice variable.
                }
                InstitutionName = rs.getString("InstitutionName");
                InstitutionNameInput.setText(InstitutionName);
                InstitutionAddress = rs.getString("InstitutionAddress");
                InstitutionAddressInput.setText(InstitutionAddress);

                StationName = rs.getString("StationName");
                StationInput.setText(StationName);

                // Modality Combobox.
                Modality = rs.getString("Modality").toUpperCase();   // Gets modality value from database.
                ModalityInput.setSelectedItem(Modality);
                selection = (String) ModalityInput.getSelectedItem();
                if(!Modality.equals(selection)){ // Selects the last one in case of doesn't match to the defined modalities.
                    System.out.println("New modality: "+Modality);
                    ModalityInput.setSelectedIndex(ModalityInput.getItemCount()-1);
                    ModalityOtherInput.setText(Modality);   // Assign the value of not matched modality to the alternative text field. WARNING: Doesn't write if lenght > 3.
                    //Modality = (String) ModalityInput.getSelectedItem();    //Assign the last selection value to modality variable.
                }else{
                    ModalityOtherInput.setText("");
                }
                
            }
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(JFrameBase.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        infoDialog = new javax.swing.JDialog();
        infoTextArea = new javax.swing.JTextArea();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        PACSConfigLayeredPane = new javax.swing.JLayeredPane();
        LocationServerLabel = new javax.swing.JLabel();
        LocationServerInput = new javax.swing.JTextField();
        SelectedServerLabel = new javax.swing.JLabel();
        AETitleServerInput = new javax.swing.JTextField();
        IPServerLabel = new javax.swing.JLabel();
        IPServerInput = new javax.swing.JTextField();
        ServerTest = new javax.swing.JButton();
        PortServerInput1 = new javax.swing.JTextField();
        PortServerLabel1 = new javax.swing.JLabel();
        AETitleServerLabel = new javax.swing.JLabel();
        SelectedServer_Input = new javax.swing.JComboBox();
        ServerDeleteButton = new javax.swing.JButton();
        ServerNameLabel = new javax.swing.JLabel();
        ServerNameInput = new javax.swing.JTextField();
        DeviceConfigLayeredPane = new javax.swing.JLayeredPane();
        ModalityLabel = new javax.swing.JLabel();
        AETitleLabel = new javax.swing.JLabel();
        ModalityInput = new javax.swing.JComboBox(LLib.getModality());
        ModalityOtherInput = new javax.swing.JTextField(ModalityMaxlenght);
        DeviceTest = new javax.swing.JButton();
        AETitleInput = new javax.swing.JTextField();
        IPLabel = new javax.swing.JLabel();
        IPInput = new javax.swing.JTextField();
        PortLabel = new javax.swing.JLabel();
        PortInput = new javax.swing.JTextField();
        Station_Label = new javax.swing.JLabel();
        AdquisitionDeviceCS_Label = new javax.swing.JLabel();
        LocationInput = new javax.swing.JTextField();
        StationInput = new javax.swing.JTextField();
        LocationLabel = new javax.swing.JLabel();
        DeviceUIDLabel = new javax.swing.JLabel();
        AcquisitionDeviceTypeCS_Input = new javax.swing.JComboBox(LLib.getAcquisitionDeviceType());
        TestUIDLabel = new javax.swing.JLabel();
        DeviceUIDInput = new javax.swing.JTextField();
        InstitutionNameLabel = new javax.swing.JLabel();
        DeviceManufacturerLabel = new javax.swing.JLabel();
        InstitutionNameInput = new javax.swing.JTextField();
        DeviceManufacturerInput = new javax.swing.JTextField();
        InstitutionAddressLabel = new javax.swing.JLabel();
        InstitutionAddressInput = new javax.swing.JTextField();
        UIDValueInput = new javax.swing.JTextField();
        UIDNameInput = new javax.swing.JTextField();
        UserConfigLayeredPane = new javax.swing.JLayeredPane();
        PhysicianNameLabel1 = new javax.swing.JLabel();
        PerformingPhysicianNameInput2 = new javax.swing.JTextField();
        PhysicianSurnameLabel = new javax.swing.JLabel();
        PerformingPhysicianSurnameInput = new javax.swing.JTextField();
        PhysicianIdLabel1 = new javax.swing.JLabel();
        PerformingPhysicianIdInput1 = new javax.swing.JTextField();
        PhysicianDeleteButton = new javax.swing.JButton();
        SelectedUserLabel = new javax.swing.JLabel();
        SelectedUser_Input1 = new javax.swing.JComboBox();
        PasswordConfigLayeredPane = new javax.swing.JLayeredPane();
        NewPasswordInput = new javax.swing.JPasswordField();
        NewPasswordLabel = new javax.swing.JLabel();
        TypePasswordInput = new javax.swing.JPasswordField();
        TypePasswordLabel = new javax.swing.JLabel();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        infoDialog.setVisible(false);
        infoDialog.setTitle("Panel de Información");
        infoDialog.setAlwaysOnTop(true);
        infoDialog.setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        infoDialog.setLocationRelativeTo(this);
        infoDialog.setSize(300, 120);
        infoDialog.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        infoDialog.setIconImage(null);
        infoDialog.setLocationByPlatform(true);
        infoDialog.setResizable(false);
        infoDialog.setUndecorated(true);

        infoTextArea.setBackground(java.awt.SystemColor.activeCaptionBorder);
        infoTextArea.setColumns(20);
        infoTextArea.setEditable(false);
        infoTextArea.setFont(new java.awt.Font("Rockwell", 1, 12));
        infoTextArea.setForeground(java.awt.SystemColor.textHighlight);
        infoTextArea.setLineWrap(true);
        infoTextArea.setRows(5);
        infoTextArea.setWrapStyleWord(true);
        infoTextArea.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.SystemColor.activeCaption));
        infoTextArea.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                infoMouseMoved(evt);
            }
        });

        javax.swing.GroupLayout infoDialogLayout = new javax.swing.GroupLayout(infoDialog.getContentPane());
        infoDialog.getContentPane().setLayout(infoDialogLayout);
        infoDialogLayout.setHorizontalGroup(
            infoDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(infoTextArea, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
        );
        infoDialogLayout.setVerticalGroup(
            infoDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(infoTextArea, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(jTextPane1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Panel de configuración del equipo");
        setResizable(false);
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                MouseMoved(evt);
            }
        });

        jButton1.setText("Guardar cambios");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        PACSConfigLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Configuración del servidor PACS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        LocationServerLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        LocationServerLabel.setText("Ubicación");
        LocationServerLabel.setBounds(20, 90, 230, 20);
        PACSConfigLayeredPane.add(LocationServerLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //LocationServerInput.setDocument(new libraries.JTextFieldLimit(LocationMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(LocationMaxlenght);
        jtff.setUpperCase(true);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        LocationServerInput.setDocument(jtff);
        LocationServerInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LocationServerInputActionPerformed(evt);
            }
        });
        LocationServerInput.setBounds(190, 90, 200, 25);
        PACSConfigLayeredPane.add(LocationServerInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SelectedServerLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        SelectedServerLabel.setText("Servidor a modificar");
        SelectedServerLabel.setBounds(20, 30, 230, 20);
        PACSConfigLayeredPane.add(SelectedServerLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //AETitleServerInput.setDocument(new libraries.JTextFieldLimit(AETitleMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(AETitleMaxlenght);
        jtff.setUpperCase(true);
        AETitleServerInput.setDocument(jtff);
        AETitleServerInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AETitleServerInputActionPerformed(evt);
            }
        });
        AETitleServerInput.setBounds(190, 120, 200, 25);
        PACSConfigLayeredPane.add(AETitleServerInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        IPServerLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        IPServerLabel.setText("IP del servidor");
        IPServerLabel.setBounds(20, 150, 230, 20);
        PACSConfigLayeredPane.add(IPServerLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //IPServerInput.setDocument(new libraries.JTextFieldLimit(IPMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(IPMaxlenght);
        jtff.setSymbolAccepted(true);
        IPServerInput.setDocument(jtff);
        IPServerInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                IPServerInputActionPerformed(evt);
            }
        });
        IPServerInput.setBounds(190, 150, 140, 25);
        PACSConfigLayeredPane.add(IPServerInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ServerTest.setText("Test");
        ServerTest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ServerTestActionPerformed(evt);
            }
        });
        ServerTest.setBounds(333, 150, 60, 25);
        PACSConfigLayeredPane.add(ServerTest, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //PortServerInput1.setDocument(new libraries.JTextFieldLimit(PortMaxlenght,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setLimit(PortMaxlenght);
        PortServerInput1.setDocument(jtff);
        PortServerInput1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PortServerInput1ActionPerformed(evt);
            }
        });
        PortServerInput1.setBounds(190, 180, 200, 25);
        PACSConfigLayeredPane.add(PortServerInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PortServerLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        PortServerLabel1.setText("Puerto del servidor");
        PortServerLabel1.setBounds(20, 180, 230, 20);
        PACSConfigLayeredPane.add(PortServerLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AETitleServerLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        AETitleServerLabel.setText("AE Title del servidor");
        AETitleServerLabel.setBounds(20, 120, 230, 20);
        PACSConfigLayeredPane.add(AETitleServerLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SelectedServer_Input.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectedServer_InputActionPerformed(evt);
            }
        });
        SelectedServer_Input.setBounds(190, 30, 200, 20);
        PACSConfigLayeredPane.add(SelectedServer_Input, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ServerDeleteButton.setText("Eliminar servidor seleccionado");
        ServerDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ServerDeleteButtonActionPerformed(evt);
            }
        });
        ServerDeleteButton.setBounds(190, 220, 200, 25);
        PACSConfigLayeredPane.add(ServerDeleteButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ServerNameLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        ServerNameLabel.setText("Nombre del servidor");
        ServerNameLabel.setBounds(20, 60, 230, 20);
        PACSConfigLayeredPane.add(ServerNameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //AETitleServerInput.setDocument(new libraries.JTextFieldLimit(AETitleMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(ServerMaxlenght);
        jtff.setUpperCase(true);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        ServerNameInput.setDocument(jtff);
        ServerNameInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ServerNameInputActionPerformed(evt);
            }
        });
        ServerNameInput.setBounds(190, 60, 200, 25);
        PACSConfigLayeredPane.add(ServerNameInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DeviceConfigLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Configuración del equipo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        ModalityLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        ModalityLabel.setText("Modalidad");
        ModalityLabel.setBounds(20, 300, 230, 20);
        DeviceConfigLayeredPane.add(ModalityLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AETitleLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        AETitleLabel.setText("AE Title del equipo");
        AETitleLabel.setBounds(20, 330, 230, 20);
        DeviceConfigLayeredPane.add(AETitleLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ModalityInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ModalityInputActionPerformed(evt);
            }
        });
        ModalityInput.setBounds(270, 300, 110, 20);
        DeviceConfigLayeredPane.add(ModalityInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //ModalityOtherInput.setDocument(new libraries.JTextFieldLimit(ModalityMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(ModalityMaxlenght);
        jtff.setUpperCase(true);
        ModalityOtherInput.setDocument(jtff);
        ModalityOtherInput.setEditable(false);
        ModalityOtherInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ModalityOtherInputActionPerformed(evt);
            }
        });
        ModalityOtherInput.setBounds(390, 300, 90, 25);
        DeviceConfigLayeredPane.add(ModalityOtherInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DeviceTest.setText("Test");
        DeviceTest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeviceTestActionPerformed(evt);
            }
        });
        DeviceTest.setBounds(420, 360, 60, 25);
        DeviceConfigLayeredPane.add(DeviceTest, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //AETitleInput.setDocument(new libraries.JTextFieldLimit(AETitleMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(AETitleMaxlenght);
        jtff.setUpperCase(true);
        AETitleInput.setDocument(jtff);
        AETitleInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AETitleInputActionPerformed(evt);
            }
        });
        AETitleInput.setBounds(270, 330, 210, 25);
        DeviceConfigLayeredPane.add(AETitleInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        IPLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        IPLabel.setText("IP del equipo");
        IPLabel.setBounds(20, 360, 230, 20);
        DeviceConfigLayeredPane.add(IPLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //IPInput.setDocument(new libraries.JTextFieldLimit(IPMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(IPMaxlenght);
        jtff.setSymbolAccepted(true);
        IPInput.setDocument(jtff);
        IPInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                IPInputActionPerformed(evt);
            }
        });
        IPInput.setBounds(270, 360, 140, 25);
        DeviceConfigLayeredPane.add(IPInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        PortLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        PortLabel.setText("Puerto del equipo");
        PortLabel.setBounds(20, 390, 230, 20);
        DeviceConfigLayeredPane.add(PortLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //PortInput.setDocument(new libraries.JTextFieldLimit(PortMaxlenght,true,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.NUMERIC);
        jtff.setLimit(PortMaxlenght);
        jtff.setNegativeAccepted(false);
        PortInput.setDocument(jtff);
        PortInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PortInputActionPerformed(evt);
            }
        });
        PortInput.setBounds(270, 390, 210, 25);
        DeviceConfigLayeredPane.add(PortInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        Station_Label.setFont(new java.awt.Font("Tahoma", 0, 12));
        Station_Label.setText("Estación");
        Station_Label.setBounds(20, 240, 230, 20);
        DeviceConfigLayeredPane.add(Station_Label, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AdquisitionDeviceCS_Label.setFont(new java.awt.Font("Tahoma", 0, 12));
        AdquisitionDeviceCS_Label.setText("Código del tipo de dispositivo de adquisición ");
        AdquisitionDeviceCS_Label.setBounds(20, 150, 250, 20);
        DeviceConfigLayeredPane.add(AdquisitionDeviceCS_Label, javax.swing.JLayeredPane.DEFAULT_LAYER);
        AdquisitionDeviceCS_Label.setVisible(false);

        //LocationInput.setDocument(new libraries.JTextFieldLimit(LocationMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(LocationMaxlenght);
        jtff.setUpperCase(true);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        LocationInput.setDocument(jtff);
        LocationInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LocationInputActionPerformed(evt);
            }
        });
        LocationInput.setBounds(270, 270, 210, 25);
        DeviceConfigLayeredPane.add(LocationInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //StationInput.setDocument(new libraries.JTextFieldLimit(DeviceMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(DeviceMaxlenght);
        jtff.setUpperCase(true);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        StationInput.setDocument(jtff);
        StationInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StationInputActionPerformed(evt);
            }
        });
        StationInput.setBounds(270, 240, 210, 25);
        DeviceConfigLayeredPane.add(StationInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        LocationLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        LocationLabel.setText("Ubicación");
        LocationLabel.setBounds(20, 270, 230, 20);
        DeviceConfigLayeredPane.add(LocationLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DeviceUIDLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        DeviceUIDLabel.setText("UID asignado al dispositivo");
        DeviceUIDLabel.setBounds(20, 60, 230, 20);
        DeviceConfigLayeredPane.add(DeviceUIDLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AcquisitionDeviceTypeCS_Input.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AcquisitionDeviceTypeCS_InputActionPerformed(evt);
            }
        });
        AcquisitionDeviceTypeCS_Input.setBounds(270, 150, 210, 20);
        DeviceConfigLayeredPane.add(AcquisitionDeviceTypeCS_Input, javax.swing.JLayeredPane.DEFAULT_LAYER);
        AcquisitionDeviceTypeCS_Input.setVisible(false);

        TestUIDLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        TestUIDLabel.setText("UID asignado a la prueba");
        TestUIDLabel.setBounds(20, 90, 230, 20);
        DeviceConfigLayeredPane.add(TestUIDLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DeviceUIDInput.setDocument(new libraries.JTextFieldLimit(StudyUIDMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(StudyUIDMaxlenght);
        jtff.setSymbolAccepted(true);
        DeviceUIDInput.setDocument(jtff);
        DeviceUIDInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeviceUIDInputActionPerformed(evt);
            }
        });
        DeviceUIDInput.setBounds(270, 60, 210, 25);
        DeviceConfigLayeredPane.add(DeviceUIDInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        InstitutionNameLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        InstitutionNameLabel.setText("Nombre del centro");
        InstitutionNameLabel.setBounds(20, 180, 230, 20);
        DeviceConfigLayeredPane.add(InstitutionNameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DeviceManufacturerLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        DeviceManufacturerLabel.setText("Fabricante");
        DeviceManufacturerLabel.setBounds(20, 30, 230, 20);
        DeviceConfigLayeredPane.add(DeviceManufacturerLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //InstitutionNameInput.setDocument(new libraries.JTextFieldLimit(InstitutionNameMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(InstitutionNameMaxlenght);
        jtff.setUpperCase(true);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        InstitutionNameInput.setDocument(jtff);
        InstitutionNameInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InstitutionNameInputActionPerformed(evt);
            }
        });
        InstitutionNameInput.setBounds(270, 180, 210, 25);
        DeviceConfigLayeredPane.add(InstitutionNameInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DeviceManufacturerInput.setDocument(new libraries.JTextFieldLimit(DeviceManufacturerMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(DeviceManufacturerMaxlenght);
        jtff.setSpaceAccepted(true);
        jtff.setSymbolAccepted(true);
        DeviceManufacturerInput.setDocument(jtff);
        DeviceManufacturerInput.setEditable(false);
        DeviceManufacturerInput.setText("UPNA - SNS/Osasunbidea");
        DeviceManufacturerInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeviceManufacturerInputActionPerformed(evt);
            }
        });
        DeviceManufacturerInput.setBounds(270, 30, 210, 25);
        DeviceConfigLayeredPane.add(DeviceManufacturerInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        InstitutionAddressLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        InstitutionAddressLabel.setText("Dirección del centro");
        InstitutionAddressLabel.setBounds(20, 210, 230, 20);
        DeviceConfigLayeredPane.add(InstitutionAddressLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //InstitutionNameInput.setDocument(new libraries.JTextFieldLimit(InstitutionNameMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(InstitutionAddressMaxlenght);
        jtff.setUpperCase(true);
        jtff.setSymbolAccepted(true);
        jtff.setSpaceAccepted(true);
        InstitutionNameInput.setDocument(jtff);
        InstitutionAddressInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InstitutionAddressInputActionPerformed(evt);
            }
        });
        InstitutionAddressInput.setBounds(270, 210, 210, 25);
        DeviceConfigLayeredPane.add(InstitutionAddressInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DeviceUIDInput.setDocument(new libraries.JTextFieldLimit(StudyUIDMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(StudyUIDMaxlenght);
        jtff.setSymbolAccepted(true);
        //UIDValueInput.setDocument(jtff);
        int UIDValue = XMLreader.getArrayList().indexOf(Def_modalityUID);
        UIDValueInput.setText(XMLreader.getArrayList().get(UIDValue+1));
        UIDValueInput.setEditable(false);
        UIDValueInput.setBounds(270, 120, 210, 25);
        DeviceConfigLayeredPane.add(UIDValueInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

        //DeviceUIDInput.setDocument(new libraries.JTextFieldLimit(StudyUIDMaxlenght,true));
        jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
        jtff.setLimit(StudyUIDMaxlenght);
        jtff.setSymbolAccepted(true);
        //UIDNameInput.setDocument(jtff);
        UIDNameInput.setText(Def_modalityUID);
        UIDNameInput.setBounds(270, 90, 210, 25);
        DeviceConfigLayeredPane.add(UIDNameInput, javax.swing.JLayeredPane.DEFAULT_LAYER);
        //UIDNameInput.setText(this.Def_modalityUID.toString()));

    UserConfigLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Gestión de usuarios", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

    PhysicianNameLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
    PhysicianNameLabel1.setText("Nombre");
    PhysicianNameLabel1.setBounds(20, 60, 120, 20);
    UserConfigLayeredPane.add(PhysicianNameLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    //PerformingPhysicianNameInput2.setDocument(new libraries.JTextFieldLimit(PerformingPhysicianNameInput2length));
    jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
    jtff.setLimit(PerformingPhysicianNameInput2length);
    jtff.setUpperCase(true);
    jtff.setSpaceAccepted(true);
    PerformingPhysicianNameInput2.setDocument(jtff);
    PerformingPhysicianNameInput2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PerformingPhysicianNameInput2ActionPerformed(evt);
        }
    });
    PerformingPhysicianNameInput2.setBounds(270, 60, 210, 25);
    UserConfigLayeredPane.add(PerformingPhysicianNameInput2, javax.swing.JLayeredPane.DEFAULT_LAYER);

    PhysicianSurnameLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
    PhysicianSurnameLabel.setText("Apellidos");
    PhysicianSurnameLabel.setBounds(20, 90, 120, 20);
    UserConfigLayeredPane.add(PhysicianSurnameLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

    //PerformingPhysicianSurnameInput2.setDocument(new libraries.JTextFieldLimit(PerformingPhysicianSurnameInput2length));
    jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
    jtff.setLimit(PerformingPhysicianSurnameInput2length);
    jtff.setUpperCase(true);
    jtff.setSpaceAccepted(true);
    PerformingPhysicianSurnameInput.setDocument(jtff);
    PerformingPhysicianSurnameInput.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PerformingPhysicianSurnameInputActionPerformed(evt);
        }
    });
    PerformingPhysicianSurnameInput.setBounds(270, 90, 210, 25);
    UserConfigLayeredPane.add(PerformingPhysicianSurnameInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

    PhysicianIdLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
    PhysicianIdLabel1.setText("DNI");
    PhysicianIdLabel1.setBounds(20, 120, 120, 20);
    UserConfigLayeredPane.add(PhysicianIdLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    //PerformingPhysicianIdInput1.setDocument(new libraries.JTextFieldLimit(PerformingPhysicianIdInput1length, true, true));
    jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
    jtff.setLimit(PerformingPhysicianIdInput1length);
    jtff.setUpperCase(true);
    PerformingPhysicianIdInput1.setDocument(jtff);
    PerformingPhysicianIdInput1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PerformingPhysicianIdInput1ActionPerformed(evt);
        }
    });
    PerformingPhysicianIdInput1.setBounds(270, 120, 210, 25);
    UserConfigLayeredPane.add(PerformingPhysicianIdInput1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    PhysicianDeleteButton.setText("Eliminar usuario seleccionado");
    PhysicianDeleteButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PhysicianDeleteButtonActionPerformed(evt);
        }
    });
    PhysicianDeleteButton.setBounds(270, 160, 210, 25);
    UserConfigLayeredPane.add(PhysicianDeleteButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

    SelectedUserLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
    SelectedUserLabel.setText("Seleccion del usuario");
    SelectedUserLabel.setBounds(20, 30, 230, 20);
    UserConfigLayeredPane.add(SelectedUserLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

    SelectedUser_Input1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SelectedUser_Input1ActionPerformed(evt);
        }
    });
    SelectedUser_Input1.setBounds(270, 30, 210, 20);
    UserConfigLayeredPane.add(SelectedUser_Input1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    PasswordConfigLayeredPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cambio de contraseña de configuración", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

    //NewPasswordInput.setDocument(new libraries.JTextFieldLimit(PasswordMaxlenght,true,false));
    jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
    jtff.setLimit(PasswordMaxlenght);
    jtff.setSymbolAccepted(true);
    jtff.setSpaceAccepted(true);
    NewPasswordInput.setDocument(jtff);
    NewPasswordInput.setBounds(190, 70, 200, 25);
    PasswordConfigLayeredPane.add(NewPasswordInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

    NewPasswordLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
    NewPasswordLabel.setText("Cambio de contraseña");
    NewPasswordLabel.setBounds(20, 70, 160, 20);
    PasswordConfigLayeredPane.add(NewPasswordLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

    //TypePasswordInput.setDocument(new libraries.JTextFieldLimit(PasswordMaxlenght,true,false));
    jtff = new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC);
    jtff.setLimit(PasswordMaxlenght);
    jtff.setSymbolAccepted(true);
    jtff.setSpaceAccepted(true);
    TypePasswordInput.setDocument(jtff);
    TypePasswordInput.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            TypePasswordInputActionPerformed(evt);
        }
    });
    TypePasswordInput.setBounds(190, 40, 200, 25);
    PasswordConfigLayeredPane.add(TypePasswordInput, javax.swing.JLayeredPane.DEFAULT_LAYER);

    TypePasswordLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
    TypePasswordLabel.setText("Contraseña de configuración");
    TypePasswordLabel.setBounds(20, 40, 160, 20);
    PasswordConfigLayeredPane.add(TypePasswordLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(DeviceConfigLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 501, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(PACSConfigLayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addComponent(UserConfigLayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
                    .addGap(10, 10, 10)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)))
                        .addComponent(PasswordConfigLayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE))))
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(DeviceConfigLayeredPane)
                .addComponent(PACSConfigLayeredPane, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(PasswordConfigLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(47, 47, 47))
                .addGroup(layout.createSequentialGroup()
                    .addComponent(UserConfigLayeredPane, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())))
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void StationInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StationInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_StationInputActionPerformed

    private void LocationInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LocationInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_LocationInputActionPerformed

    private void AETitleInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AETitleInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_AETitleInputActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
         
        // Gets DEVICE DATA from forms.
        DeviceAETitle = AETitleInput.getText();
        DeviceLocation = LocationInput.getText();
        DeviceIP = IPInput.getText();  
        String trueIP = IPtest(DeviceIP,6,false);        // 0: IP | 1: HostName
        DeviceIP = trueIP;
        IPInput.setText(trueIP);
        
        String DevicePort_String = PortInput.getText();
        if(DevicePort_String.length() != 0){            
            DevicePort = Integer.parseInt(DevicePort_String);
        }else{
            DevicePort = Def_DevicePort;
            PortInput.setText(Integer.toString(DevicePort));
        }  
        DeviceManufacturer = DeviceManufacturerInput.getText();
        DeviceUID = (String) DeviceUIDInput.getText();
        
        InstanceUID = (String) UIDValueInput.getText();
        //InstanceUID = (String) UIDComboBox.getSelectedItem();
        
        // Get's AcquisitionDeviceTypeCodeSequence data:
            String[] ADTCS_values = LLib.getAcquisitionDeviceType();
            AcquisitionDeviceTypeCodeSequence = ADTCS_values[AcquisitionDeviceTypeCS_Input.getSelectedIndex()];
        InstitutionName = InstitutionNameInput.getText();
        InstitutionAddress = InstitutionAddressInput.getText();
        StationName = StationInput.getText();
        // Get's Modality data:
        if(ModalityOtherInput.isEditable() && ModalityOtherInput.getText().length() != 0){
            Modality = ModalityOtherInput.getText();
        }else{
            String[] ModalityList = LLib.getModality();
            //Modality = ModalityList[ModalityInput.getSelectedIndex()];
            Modality = (String) ModalityInput.getSelectedItem();
        }
        System.out.println("Modality"+Modality);
        
        // Gets SERVER DATA from forms.
        String SelectedServerName = null;
        if(SelectedServer_Input.getSelectedItem() != null){
            SelectedServerName = SelectedServer_Input.getSelectedItem().toString();
        }
        ServerName = ServerNameInput.getText();
        ServerAETitle = AETitleServerInput.getText();        
        
        ServerLocation = LocationServerInput.getText();        
        ServerIP = IPServerInput.getText();
        trueIP = IPtest(ServerIP,7,false);        // 0: IP | 1: HostName 
        ServerIP = trueIP;
        IPServerInput.setText(trueIP);
                
        String ServerPort_String = PortServerInput1.getText();
        System.out.println("ServerPort_String: "+ServerPort_String);
        if(ServerPort_String.length() != 0){            
            ServerPort = Integer.parseInt(ServerPort_String);
        }else{
            ServerPort = Def_ServerPort;
            PortServerInput1.setText(Integer.toString(ServerPort));
        }
        
        // Gets PHYSICIANS DATA from forms.
        String SelectedPhysiciansName = null;
        if(SelectedUser_Input1.getSelectedItem() != null){
            SelectedPhysiciansName = SelectedUser_Input1.getSelectedItem().toString();
        }
        String PerformingPhysiciansName = PerformingPhysicianNameInput2.getText();
        String PerformingPhysiciansSurName = PerformingPhysicianSurnameInput.getText();
        String PhysicianId = PerformingPhysicianIdInput1.getText();

        System.out.println("PerformingPhysiciansName: "+PerformingPhysiciansName+" PerformingPhysiciansSurName: "+PerformingPhysiciansSurName+" PhysicianId: "+PhysicianId);

        // Gets PASSWORD DATA from forms.
        // OLD Password check.
        String ConfigPassword = TypePasswordInput.getText();   
        int Pass = passwordCheck(ConfigPassword);   // Validates the password.

        // NEW Password check.
        newConfigPassword = NewPasswordInput.getText();
        System.out.println("newConfigPassword: "+newConfigPassword);

        if(newConfigPassword.length() == 0){
            newConfigPassword = MD5.getEncoded(ConfigPassword);     // Case of new PW field is empty, keeps old PW.
            System.out.println("newConfigPassword: "+newConfigPassword);
        }else{  // Case of new PW field is filled, calculate MD5 hash.
            newConfigPassword = MD5.getEncoded(newConfigPassword);
            System.out.println("newConfigPassword: "+newConfigPassword);
        }        
        System.out.println("DeviceAETitle: "+DeviceAETitle+"\nDeviceLocation: "+DeviceLocation+"\nDeviceIP: "+DeviceIP+"\nDevicePort: "+DevicePort+"\nInstanceUID: "+InstanceUID+"\nAcquisitionDeviceTypeCodeSequence: "+AcquisitionDeviceTypeCodeSequence+"\nStationName: "+StationName+"\nModality: "+Modality+"\nConfigPassword: "+ConfigPassword);
        // Error collection.
        try{
            /*if(ServerName.length() == 0 && ServerAETitle.length() == 0 && ServerLocation.length() == 0 && ServerIP.length() == 0 && ServerPort_String.length() == 0){
                // All data of servers is empty, so don't perform changes.
            }else if(PhysicianId.length() == 0 && PerformingPhysiciansName.length() == 0 && PerformingPhysiciansSurName.length() == 0 ){
                // All physician's data is empty, so don't perform changes.
            }else */

            // Device configuration incomplete.
            if(DeviceManufacturer.length() == 0 || DeviceUID.length() == 0 || InstanceUID.length() == 0 || AcquisitionDeviceTypeCodeSequence.length() == 0 || InstitutionName.length() == 0 || StationName.length() == 0 || DeviceAETitle.length() == 0 || DeviceIP.length() == 0){
                Pass = 1;
                ShowError(0);
            // Performing physician's configuration incomplete.
            }else if(!UIDUtils.isValidUID(DeviceUID)){
                Pass = 1;
                ShowError(14);
            }else if((PerformingPhysiciansName.length() == 0 || PerformingPhysiciansSurName.length() == 0 || PhysicianId.length() == 0)
                && !(SelectedPhysiciansName == null && PerformingPhysiciansName.length() == 0 && PerformingPhysiciansSurName.length() == 0 && PhysicianId.length() == 0)){
                Pass = 1;
                ShowError(10);

            // Server configuration incomplete.
            }else if((ServerName.length() == 0 || ServerAETitle.length() == 0 || ServerLocation.length() == 0 || ServerIP.length() == 0)
                && !(SelectedServerName == null && ServerName.length() == 0 && ServerAETitle.length() == 0 && ServerLocation.length() == 0)){
                Pass = 1;
                ShowError(11);
            }else if((SelectedUser_Input1.getItemCount() == 1) && (SelectedPhysiciansName == null && PerformingPhysiciansName.length() == 0 && PerformingPhysiciansSurName.length() == 0 && PhysicianId.length() == 0)){
                Pass = 1;
                ShowError(12);
            }else if((SelectedServer_Input.getItemCount() == 1) && (SelectedServerName == null && ServerName.length() == 0 && ServerAETitle.length() == 0 && ServerLocation.length() == 0)){
                Pass = 1;
                ShowError(13);
            }else if(ConfigPassword.length() == 0){
                Pass = 1;
                ShowError(1);
            }else if(Pass != 0){
                Pass = 1;
                ShowError(2);
            }else{     
                // Table device: if there are not errors, saves written values on database (only one device per table)
                Object[] var = new Object[]{null, DeviceAETitle, DeviceLocation, DeviceIP, DevicePort, DeviceUID, InstanceUID, AcquisitionDeviceTypeCodeSequence, StationName, Modality, newConfigPassword,DeviceManufacturer,InstitutionName,InstitutionAddress};
                DB.SQLupdate("REPLACE INTO device VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)", false, var.length, var);
                // Table server.
                if(!(SelectedServerName == null && ServerName.length() == 0 && ServerAETitle.length() == 0 && ServerLocation.length() == 0)){
                    Object[] var2 = new Object[]{null, ServerName, ServerAETitle, ServerLocation, ServerIP, ServerPort};
                    DB.SQLupdate("REPLACE INTO server VALUES(?,?,?,?,?,?)", false, var2.length, var2);
                }
                // Table deviceserver.
                /*Integer DeviceId = ;
                Integer ServerId = ;
                Object[] var3 = new Object[]{DeviceId, ServerId};
                DB.SQLupdate("REPLACE INTO deviceserver VALUES(?,?)", false, var2.length, var2);*/
                // Table physician.
                if(!(SelectedPhysiciansName == null && PerformingPhysiciansName.length() == 0 && PerformingPhysiciansSurName.length() == 0 && PhysicianId.length() == 0)){
                    Object[] var4 = new Object[]{null, PhysicianId, PerformingPhysiciansName, PerformingPhysiciansSurName};
                    DB.SQLupdate("REPLACE INTO physician VALUES(?,?,?,?)", false, var4.length, var4);
                    System.out.println("MIAU");            
                }
                System.out.println("MIAU");
                ShowError(3);
                this.setVisible(false);                
            }
        }catch (SQLException ex) {
                ShowError(5);                                
                Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, "Incorrect data format: can't write on database", ex);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void IPInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IPInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_IPInputActionPerformed

    private void AETitleServerInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AETitleServerInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_AETitleServerInputActionPerformed

    private void IPServerInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IPServerInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_IPServerInputActionPerformed

    private void TypePasswordInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TypePasswordInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TypePasswordInputActionPerformed

    private void ModalityInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModalityInputActionPerformed
        // TODO add your handling code here:
                
        if(ModalityInput.getSelectedIndex() == ModalityInput.getItemCount()-1){ // Selección del último componente (OT)
            ModalityOtherInput.setEditable(true);
            // !!! Allow only capital letters.
        }else{
            ModalityOtherInput.setText(null);
            ModalityOtherInput.setEditable(false);
        }

        // Gets the corresponding Info mensaje from LanguajeLibrary:
        int infoModalityNmb = ModalityInput.getSelectedIndex();
        Object[] infoModalityText = LLib.displayInfoModality(infoModalityNmb);
        infoTextArea.setText(infoModalityText[0].toString());
        infoDialog.setLocationRelativeTo(UserConfigLayeredPane);
        infoDialog.setVisible(true);
    }//GEN-LAST:event_ModalityInputActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MouseMoved
        // TODO add your handling code here:
        infoDialog.setVisible(false);
    }//GEN-LAST:event_MouseMoved

    private void infoMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infoMouseMoved
        // TODO add your handling code here:
        infoDialog.setVisible(false);
    }//GEN-LAST:event_infoMouseMoved

    private void PortServerInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PortServerInput1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PortServerInput1ActionPerformed

    private void PortInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PortInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PortInputActionPerformed

    private void LocationServerInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LocationServerInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_LocationServerInputActionPerformed

    private void ModalityOtherInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModalityOtherInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ModalityOtherInputActionPerformed

    private void SelectedServer_InputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SelectedServer_InputActionPerformed
        fillServerData();
    }//GEN-LAST:event_SelectedServer_InputActionPerformed

    private void DeviceTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeviceTestActionPerformed
        // TODO add your handling code here:
        String trueIP = IPtest(IPInput.getText(),6,true);
        IPInput.setText(trueIP);
    }//GEN-LAST:event_DeviceTestActionPerformed

    private void ServerTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ServerTestActionPerformed
        // TODO add your handling code here:
        String trueIP = IPtest(IPServerInput.getText(),7,true);
        IPServerInput.setText(trueIP);
    }//GEN-LAST:event_ServerTestActionPerformed

    private void PerformingPhysicianNameInput2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PerformingPhysicianNameInput2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PerformingPhysicianNameInput2ActionPerformed

    private void PerformingPhysicianSurnameInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PerformingPhysicianSurnameInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PerformingPhysicianSurnameInputActionPerformed

    private void PerformingPhysicianIdInput1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PerformingPhysicianIdInput1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_PerformingPhysicianIdInput1ActionPerformed

    private void PhysicianDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PhysicianDeleteButtonActionPerformed
        deletePhysiciansData();
    }//GEN-LAST:event_PhysicianDeleteButtonActionPerformed

    private void AcquisitionDeviceTypeCS_InputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AcquisitionDeviceTypeCS_InputActionPerformed
        // Gets the corresponding Info mensaje from LanguajeLibrary:
        String infoAcquisitionDeviceTypeCS = AcquisitionDeviceTypeCS_Input.getSelectedItem().toString();
        String infoAcquisitionDeviceTypeCS_Text = LLib.getAcquisitionDeviceCID(infoAcquisitionDeviceTypeCS).get(2);
        infoTextArea.setText(infoAcquisitionDeviceTypeCS_Text);
        infoDialog.setLocationRelativeTo(UserConfigLayeredPane);
        infoDialog.setVisible(true);
    }//GEN-LAST:event_AcquisitionDeviceTypeCS_InputActionPerformed

    private void SelectedUser_Input1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SelectedUser_Input1ActionPerformed
        fillPhysiciansData();
    }//GEN-LAST:event_SelectedUser_Input1ActionPerformed

    private void ServerDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ServerDeleteButtonActionPerformed
        deleteServerData();
    }//GEN-LAST:event_ServerDeleteButtonActionPerformed

    private void ServerNameInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ServerNameInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ServerNameInputActionPerformed

    private void DeviceUIDInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeviceUIDInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DeviceUIDInputActionPerformed

    private void InstitutionNameInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InstitutionNameInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_InstitutionNameInputActionPerformed

    private void DeviceManufacturerInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeviceManufacturerInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_DeviceManufacturerInputActionPerformed

    private void InstitutionAddressInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InstitutionAddressInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_InstitutionAddressInputActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {                
                new JFrameConfig().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AETitleInput;
    private javax.swing.JLabel AETitleLabel;
    private javax.swing.JTextField AETitleServerInput;
    private javax.swing.JLabel AETitleServerLabel;
    private javax.swing.JComboBox AcquisitionDeviceTypeCS_Input;
    private javax.swing.JLabel AdquisitionDeviceCS_Label;
    private javax.swing.JLayeredPane DeviceConfigLayeredPane;
    private javax.swing.JTextField DeviceManufacturerInput;
    private javax.swing.JLabel DeviceManufacturerLabel;
    private javax.swing.JButton DeviceTest;
    private javax.swing.JTextField DeviceUIDInput;
    private javax.swing.JLabel DeviceUIDLabel;
    private javax.swing.JTextField IPInput;
    private javax.swing.JLabel IPLabel;
    private javax.swing.JTextField IPServerInput;
    private javax.swing.JLabel IPServerLabel;
    private javax.swing.JTextField InstitutionAddressInput;
    private javax.swing.JLabel InstitutionAddressLabel;
    private javax.swing.JTextField InstitutionNameInput;
    private javax.swing.JLabel InstitutionNameLabel;
    private javax.swing.JTextField LocationInput;
    private javax.swing.JLabel LocationLabel;
    private javax.swing.JTextField LocationServerInput;
    private javax.swing.JLabel LocationServerLabel;
    private javax.swing.JComboBox ModalityInput;
    private javax.swing.JLabel ModalityLabel;
    private javax.swing.JTextField ModalityOtherInput;
    private javax.swing.JPasswordField NewPasswordInput;
    private javax.swing.JLabel NewPasswordLabel;
    private javax.swing.JLayeredPane PACSConfigLayeredPane;
    private javax.swing.JLayeredPane PasswordConfigLayeredPane;
    private javax.swing.JTextField PerformingPhysicianIdInput1;
    private javax.swing.JTextField PerformingPhysicianNameInput2;
    private javax.swing.JTextField PerformingPhysicianSurnameInput;
    private javax.swing.JButton PhysicianDeleteButton;
    private javax.swing.JLabel PhysicianIdLabel1;
    private javax.swing.JLabel PhysicianNameLabel1;
    private javax.swing.JLabel PhysicianSurnameLabel;
    private javax.swing.JTextField PortInput;
    private javax.swing.JLabel PortLabel;
    private javax.swing.JTextField PortServerInput1;
    private javax.swing.JLabel PortServerLabel1;
    private javax.swing.JLabel SelectedServerLabel;
    private javax.swing.JComboBox SelectedServer_Input;
    private javax.swing.JLabel SelectedUserLabel;
    private javax.swing.JComboBox SelectedUser_Input1;
    private javax.swing.JButton ServerDeleteButton;
    private javax.swing.JTextField ServerNameInput;
    private javax.swing.JLabel ServerNameLabel;
    private javax.swing.JButton ServerTest;
    private javax.swing.JTextField StationInput;
    private javax.swing.JLabel Station_Label;
    private javax.swing.JLabel TestUIDLabel;
    private javax.swing.JPasswordField TypePasswordInput;
    private javax.swing.JLabel TypePasswordLabel;
    private javax.swing.JTextField UIDNameInput;
    private javax.swing.JTextField UIDValueInput;
    private javax.swing.JLayeredPane UserConfigLayeredPane;
    private javax.swing.JDialog infoDialog;
    private javax.swing.JTextArea infoTextArea;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables


    private void ShowError(int Error){    // Show alert window on 'save changes' button press.
        Object[] Alert_content = LLib.getError(Error);
        ImageIcon alert = (ImageIcon) Alert_content[1];
        //infoTextArea.setText(Alert_content[0].toString());
        JOptionPane.showMessageDialog(PasswordConfigLayeredPane, Alert_content[0].toString());
        //infoDialog.setVisible(true);
    }
    public String IPtest(String IP, int msg, boolean test){
            InetAddress address = null;
            try{     // Checks if requested IP value exists on the net.
                address = InetAddress.getByName(IP);                
                                
            } catch (UnknownHostException ex) {
                ShowError(msg);
                Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, "Incorrect IP adress", ex);
            }
            String HostAdress = address.getHostAddress();
            String HostName = address.getHostName();
            if(test){ShowError(8);}
            /*System.out.println("address: "+address);
            System.out.println("sHostAdress: "+HostAdress);
            System.out.println("sHostName: "+HostName);*/                        
            return HostAdress;
    }
    public void setScreenSize(){
            // Adjust Main frame's size
            screenSize = super.getToolkit().getScreenSize();
            int screenWidth = screenSize.width;
            int screenHeight = screenSize.height-30;
            Dimension frameDimension = super.getSize();
            int frameHeight = frameDimension.height;
            int frameWidth = frameDimension.width;
            super.setLocation((screenHeight-frameHeight)/2, (screenWidth-frameWidth)/2);
            //Physician.setSize(screenWidth/2-20, screenHeight/2-20);
    }    
    public void getPhysicianNames() {
        ArrayList<Physician> physicianList = new ArrayList<Physician>();
        //DB = new MySQL_Query();
        DB2Hash physician = null;
        try {
            SelectedUser_Input1.addItem(null); // Add the first server with empty value to allow creating a new one.

            rs = DB.SQLquery("SELECT * FROM physician ORDER BY PerformingPhysiciansName,PerformingPhysiciansSurName");
            rs.beforeFirst();
            while (rs.next()) {            
                physician = new DB2Hash(rs);    
                Physician currentPhysician = new Physician(physician);
                System.out.println("currentPhysician: " + currentPhysician);
                physicianList.add(currentPhysician);
                SelectedUser_Input1.addItem(currentPhysician);
            }
            //DB.closeConnection();
        } catch (SQLException ex) {
            Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, null, ex);        
        }
        // From ArrayList to String[].
        /*int size = physicianList.size();
        String[] physicianList2 = new String[size];
        physicianList.toArray(physicianList2);
        return physicianList2;*/
    }
    private void fillPhysiciansData(){
            // Filling physicians fields.
            Physician selectedPhysician = (Physician) SelectedUser_Input1.getSelectedItem();
            if(selectedPhysician != null){
                DB2Hash physician = selectedPhysician.getPhysician();
                PerformingPhysicianNameInput2.setText(physician.get("PerformingPhysiciansName"));
                PerformingPhysicianSurnameInput.setText(physician.get("PerformingPhysiciansSurName"));
                PerformingPhysicianIdInput1.setText(physician.get("PhysicianId"));
            }else{
                PerformingPhysicianNameInput2.setText(null);
                PerformingPhysicianSurnameInput.setText(null);
                PerformingPhysicianIdInput1.setText(null);
            }
                        
    }
    private void fillServerData(){
            // Filling server fields.
            Server selectedServer = (Server) SelectedServer_Input.getSelectedItem();
            if(selectedServer != null){
                DB2Hash server = selectedServer.getServer();
                ServerNameInput.setText(server.get("ServerName"));
                AETitleServerInput.setText(server.get("AETitle"));
                LocationServerInput.setText(server.get("Location"));
                IPServerInput.setText(server.get("HostIP"));
                PortServerInput1.setText(server.get("HostPort"));
            }else{
                ServerNameInput.setText(null);
                AETitleServerInput.setText(null);
                LocationServerInput.setText(null);
                IPServerInput.setText(null);
                PortServerInput1.setText(null);
            }
            
    }
    private void deletePhysiciansData(){
        JPasswordField PF = new JPasswordField();
        String txt = (String) LLib.getError(9)[0];
        int Acepted = JOptionPane.showConfirmDialog(null, PF, txt, JOptionPane.OK_CANCEL_OPTION,2);
        String passWord = PF.getText();
        //System.out.println("passWord: "+passWord);

        int Pass = passwordCheck(passWord);   // Validates the password.
        //System.out.println("Validation: "+Pass);
        if(Acepted != 0){   // Action cancelled: do nothing.
        }else if(passWord.length() == 0){
            ShowError(1);
        } else if (Pass == 0) {
            // Getting selected physicians fields.
            Physician selectedPhysician = (Physician) SelectedUser_Input1.getSelectedItem();
            DB2Hash physician = selectedPhysician.getPhysician();

            // Remove data from DB
            String Id = physician.get("Id");
            ArrayList v = new ArrayList();
            v.add(Id);
            try {
                DB.SQLupdate2("DELETE FROM physician WHERE Id=?",false,v.size(),v);
                //DB.closeConnection();
            } catch (SQLException ex) {
                Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, null, ex);
            }
            SelectedUser_Input1.removeItem(selectedPhysician);  // Removes item from combobox.
            ShowError(3);
        }else{ShowError(2);}
    }
    private void deleteServerData(){
        JPasswordField PF = new JPasswordField();
        String txt = (String) LLib.getError(9)[0];
        int Acepted = JOptionPane.showConfirmDialog(null, PF, txt, JOptionPane.OK_CANCEL_OPTION,2);
        String passWord = PF.getText();
        //System.out.println("passWord: "+passWord);

        int Pass = passwordCheck(passWord);   // Validates the password.
        //System.out.println("Validation: "+Pass);
        if(Acepted != 0){   // Action cancelled: do nothing.
        }else if(passWord.length() == 0){
            ShowError(1);
        } else if (Pass == 0) {
            // Getting selected server fields.
            Server selectedServer = (Server) SelectedServer_Input.getSelectedItem();
            DB2Hash server = selectedServer.getServer();

            // Remove data from DB
            String Id = server.get("Id");
            ArrayList v = new ArrayList();
            v.add(Id);
            try {
                DB.SQLupdate2("DELETE FROM server WHERE Id=?",false,v.size(),v);
                //DB.closeConnection();
            } catch (SQLException ex) {
                Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, null, ex);
            }
            SelectedServer_Input.removeItem(selectedServer);  // Removes item from combobox.
            ShowError(3);
        }else{ShowError(2);}
    }

    private int passwordCheck(String ConfigPassword){
        String ConfigPassword_MD5 = MD5.getEncoded(ConfigPassword.toUpperCase()); //

        String DBPassword = null;
        int Pass = 1;
        try {
            rs = DB.SQLquery("SELECT ConfigPassword FROM device");
            rs.beforeFirst();

            while(rs.next()){
                DBPassword = rs.getString("ConfigPassword");
            }
            if(DBPassword.isEmpty()){   // There is not password on the DB.
                Pass = 0;
            }else{
                Pass = ConfigPassword_MD5.compareTo(ConfigPassword_MD5);
                //System.out.println("Password comparison:"+Pass +"(ConfigPassword_MD5 = DBPassword):"+ConfigPassword_MD5+" = "+ConfigPassword_MD5);
            }

        } catch (SQLException ex) {
            ShowError(4);
            Logger.getLogger(JFrameConfig.class.getName()).log(Level.SEVERE, null, ex);
        }
        return Pass;
    }
}

